<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition  template="template.xhtml"    >
	
	<ui:define name="principal">
		
		<h:form id="frmCadastroCliente">
		
   			<p:growl id="message" 
			         showDetail="true" 
			         globalOnly="true"
			         sticky="false"
			         life="1200" />		
		  
			<p:panel header="#{msg['label.cliente.nome.tela']}"  
			         styleClass="pnFormularioCadastro">
				<h:panelGrid columns="1" >
					<p:outputLabel value="#{msg['label.cliente.cliente']}" /> 
					<p:inputText id="cliente"
					             value="#{cadastroClienteMB.cliente.nome}"
					             size="45"
					             required="true"
					             requiredMessage="#{msg['mensagem.obrigatoria']}">
					</p:inputText>	
					<p:message for="cliente" />		
					
					<p:outputLabel value="#{msg['label.cliente.apelido']}" />
					<p:inputText id="apelido"
					             value="#{cadastroClienteMB.cliente.apelido}"
					             size="45"
					             required="true"
					             requiredMessage="#{msg['mensagem.obrigatoria']}">
					</p:inputText>	
					<p:message for="apelido" />	
					
					<p:outputLabel value="#{msg['label.cliente.dataAniversario']}" />
					<p:inputMask mask="99/99/9999"
					             id="dataAniversario"
					             value="#{cadastroClienteMB.cliente.dataAniversario}">
					</p:inputMask>
					
					<p:outputLabel value="#{msg['label.fornecedor.telefone']}" />
					<p:inputText id="telefone"
					             value="#{cadastroClienteMB.cliente.telefone}" 
					             size="45" />				             

					<p:outputLabel value="#{msg['label.cliente.celular']}" />
					<p:inputText id="celular"
					             value="#{cadastroClienteMB.cliente.celular}"
					             size="45" />				            

					<p:outputLabel value="#{msg['label.cliente.email']}" />
					<p:inputText id="email"
					             value="#{cadastroClienteMB.cliente.email}"
					             size="45"
					             validatorMessage="Email inválido">	
					 	<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
					 </p:inputText>
					 <p:message for="cliente" />	
				</h:panelGrid>
				<h:panelGrid columns="1"
			      	         styleClass="pgBotoes" >
					<p:column>
						<p:commandButton value="Salvar"
								         action="#{cadastroClienteMB.salva()}"
						 				 update=":frmCadastroCliente, :frmListagemCliente" />
						<p:spacer width="20" height="0"/>
						<p:commandButton value="Limpar"
						 				 update=":frmCadastroCliente"
						 				 immediate="true" >
							<p:resetInput target=":frmCadastroCliente" />								         
						</p:commandButton>
						<p:spacer width="20" height="0"/>
						<p:commandButton value="Fechar"
						                 immediate="true"
						                 action="agenda" />								
					</p:column>
				</h:panelGrid>						
			</p:panel>
		</h:form>
		
		<h:form id="frmListagemCliente">
			<p:panel header="Clientes Cadastrados" styleClass="pnFormularioCadastro" >
				<p:dataTable id="tbCliente" 
				             value="#{cadastroClienteMB.listaCliente}" 
				             var="reg"
				             paginator="true"
				             rows="10"
				             paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				             rowsPerPageTemplate="5,10,15,20,25,30"
				             emptyMessage="Nenhum registro Encontrado" >
					<p:column headerText="Cliente"
					          width="9%">
						<p:outputLabel value="#{reg.idCliente}" />
					</p:column>	
					<p:column headerText="Descriçao"
					          width="50%">
						<p:outputLabel value="#{reg.nome}"/>
					</p:column>	
					
					<p:column headerText="Aniversário"
					          width="15%">
						<p:outputLabel value="#{reg.dataAniversario}"/>
					</p:column>
					
					<p:column headerText="Celular"
					          width="13%">
						<p:outputLabel value="#{reg.celular}"/>
					</p:column>
					
					<p:column headerText="Ações"
							  style="align: center;"		
					          width="13%">
						<p:commandLink update=":frmCadastroCliente">														            
							<h:graphicImage library="imagens" 
											name="editar.png"
											title="Editar" />
							<f:setPropertyActionListener target="#{cadastroClienteMB.cliente}" value="#{reg}" />
						</p:commandLink>
						<p:spacer width="15" />
						<p:commandLink oncomplete="PF('dlgExcluiCliente').show()" >		
							<h:graphicImage library="imagens" 
											name="excluir.png"
											title="Deletar" />
							<f:setPropertyActionListener target="#{cadastroClienteMB.cliente}" value="#{reg}" />
						</p:commandLink>
					</p:column>	
				</p:dataTable>
			</p:panel>
		</h:form>
		
		<p:dialog widgetVar="dlgExcluiCliente"  >
			<p:outputLabel value="Confirma a Exclusão do Cliente?" />
			<br />
			<br />
			<p:commandButton value="Sim"
			                 action="#{cadastroClienteMB.exclui()}"
			                 update=":frmListagemCliente, :frmCadastroCliente:message"
			                 oncomplete="PF('dlgExcluiCliente').hide()" />
			<p:spacer width="5px" />
			<p:commandButton value="Não"
			                 oncomplete="PF('dlgExcluiCliente').hide()" />
		</p:dialog>
		
	</ui:define>
	
</ui:composition>
</html>